#include "plotwindow.h"
#include "ui_plotwindow.h"

PlotWindow::PlotWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::PlotWindow)
{


    setStyle(&mystyle);
    ui->setupUi(this);

}

PlotWindow::~PlotWindow()
{
    delete ui;
}

void PlotWindow::Initialize()
{
    myplot = ui->ROIs;
    myhistogram = ui->Histogram;
    InitializePlots();

}

void PlotWindow::InitializePlots()
{
    int number = 0;
    for(int i = 0; i < 3; i++)
    {
        int color = 0;
        int r = 0;
        int g = 0;
        int b = 0;
        if(i == 0)
        {
            color = Qt::red;
            r = 255;
            g = 0;
            b = 0;
        }
        if(i == 1)
        {
            color = Qt::green;
            r = 0;
            g = 255;
            b = 0;
        }
        if(i == 2)
        {
            r = 0;
            g = 0;
            b = 255;
            color = Qt::blue;
        }
        for(int j = 0; j < 8; j++)
        {
            myplot->addGraph();
            myplot->graph(number)->setPen(QPen(QColor(r,g,b))); // line color blue for first graph
            //myplot->graph(number)->setBrush(QBrush(QColor(r,g,b,20)));
            number++;
        }
    }
    // configure right and top axis to show ticks but no labels (could've also just called customPlot->setupFullAxesBox):
    myplot->xAxis2->setVisible(true);
    myplot->xAxis2->setTickLabels(false);
    myplot->yAxis2->setVisible(true);
    myplot->yAxis2->setTickLabels(false);
    myplot->xAxis->setLabel("Frame (relative");
    myplot->yAxis->setLabel("Mean ADC (sum)");
    // set axes ranges, so we see all data:
    myplot->xAxis->setRange(0, 200);
    myplot->yAxis->setRange(0, 200);
    myplot->replot();


    myhistogram->addGraph();
    myhistogram->addGraph();
    myhistogram->addGraph();
    myhistogram->graph(0)->setPen(QPen(Qt::red)); // line color red for first graph
    myhistogram->graph(0)->setBrush(QBrush(QColor(255, 0, 0, 50))); // first graph will be filled with translucent red
    myhistogram->graph(1)->setPen(QPen(Qt::green)); // line color green for first graph
    myhistogram->graph(1)->setBrush(QBrush(QColor(0, 255, 0, 50))); // first graph will be filled with translucent green
    myhistogram->graph(2)->setPen(QPen(Qt::blue)); // line color blue for first graph
    myhistogram->graph(2)->setBrush(QBrush(QColor(0, 0, 255, 50))); // first graph will be filled with translucent blue
    // configure right and top axis to show ticks but no labels (could've also just called customPlot->setupFullAxesBox):
    myhistogram->xAxis2->setVisible(true);
    myhistogram->xAxis2->setTickLabels(false);
    myhistogram->yAxis2->setVisible(true);
    myhistogram->yAxis2->setTickLabels(false);
    myhistogram->yAxis->setLabel("Log(Frequency)");
    myhistogram->xAxis->setLabel("ADC Count (sum)");
    // set axes ranges, so we see all data:
    myhistogram->xAxis->setRange(0, 1000);
    myhistogram->yAxis->setRange(0, 100000);
    myhistogram->replot();
}
